//! 跨链支持的主链类型
//!

use std::fmt::Display;

#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Default)]
#[repr(u8)]
pub enum ChainType {
    #[default]
    Inve = 1,
    Btc = 2,
    Eth = 3,
}

impl From<u8> for ChainType {
    fn from(value: u8) -> Self {
        match value {
            1 => Self::Inve,
            2 => Self::Btc,
            3 => Self::Eth,
            _ => panic!("unsupported type"),
        }
    }
}

impl Into<u8> for ChainType {
    fn into(self) -> u8 {
        self as u8
    }
}

impl Display for ChainType {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            ChainType::Inve => f.write_str("INVE"),
            ChainType::Btc => f.write_str("BTC"),
            ChainType::Eth => f.write_str("ETH"),
        }
    }
}
